package com.example.mall.controller;

import com.example.mall.pojo.Menu;
import com.example.mall.pojo.NewSpPermission;
import com.example.mall.pojo.Rbody;
import com.example.mall.service.RightService;
import com.example.mall.utils.JwtUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@AllArgsConstructor
@CrossOrigin
public class RightController {

    RightService rightService;
    @GetMapping("/menus")
    public Rbody getMenus(HttpServletRequest request){
        Rbody rbody = new Rbody();
        String token = request.getHeader("Authorization");
        String audience = JwtUtils.getAudience(token);
        System.out.println(audience);
        List<Menu> menuList=rightService.getMenuByUserId(Integer.parseInt(audience));
        System.out.println("token is" + token);
//        System.out.println(audience);
//        List<Menu> menuList=rightService.getMenuByUserId(Integer.parseInt(audience));
//        System.out.println("token is" + token);
        rbody.setData(menuList);
        rbody.getMeta().setMsg("获取菜单成功");
        rbody.getMeta().setStatus(200);
        return  rbody;

    }

    @GetMapping("rights/list")
    public Rbody getRightList(){
        Rbody rbody = new Rbody();
        List<NewSpPermission> permissions = rightService.getList();
        NewSpPermission newSpManager = new NewSpPermission();
//        newSpManager.setId(list.);
        System.out.println("!!!!!!!!!"+permissions);
        rbody.setData(permissions);
        rbody.getMeta().setMsg("获取成功");
        rbody.getMeta().setStatus(200);

        return  rbody;
    }


}
